package com.kuaidi.service;

import com.kuaidi.entity.Address;
import com.kuaidi.repository.AddressRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressService {
    @Autowired
    private AddressRepository addressRepository;

    public List<Address> getAllAddresses() {
        return addressRepository.findAllByOrderByCreatedAtDesc();
    }

    @Transactional
    public Address createAddress(Address address) {
        return addressRepository.save(address);
    }

    @Transactional
    public void deleteAddresses(List<Long> ids) {
        addressRepository.deleteAllById(ids);
    }
}

